#!/usr/bin/env python

import gtk
import gettext
import constants
from mxit import handles
from blend import const
from signals import multimxDialogSignals

gettext.install('blendIT','locale');


class multimxDialog(gtk.Dialog):
   
   def __init__(self,blend):
      window = blend.gui.buddyWindow;
      title = _("Create MultiMx");
      gtk.Dialog.__init__(self,title, window,
                          gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
                          (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT,
                          gtk.STOCK_OK, gtk.RESPONSE_ACCEPT));

      self.blend = blend;
      sigs = multimxDialogSignals.signals(blend);
      self.set_icon_from_file(constants.IMG_MultiMx);
      self.connect('response',sigs.on_response,self);
      
      self.drawDialog();

      def sig(widget): widget.destroy();
      self.connect('close',sig);    

   def drawDialog(self):
      table = gtk.Table(rows=2,columns=2);

      # Alias
      aliasLabel = gtk.Label(_("MultiMx Name:"));
      aliasLabel.show();
      table.attach(aliasLabel,0,1,0,1,gtk.FILL);
      
      self.aliasTextEntry = gtk.Entry();
      self.aliasTextEntry.show();
      table.attach(self.aliasTextEntry,1,2,0,1,gtk.EXPAND|gtk.FILL);

      
      # Contacts
      invLabel = gtk.Label(_("Invitations:"));
      invLabel.show();
      table.attach(invLabel,0,1,1,2,gtk.FILL);

      self.checks = [];
      box = gtk.VBox();
      box.show();
      
      # Scrolled Window
      buddies = self.blend.conn.roster.all_online_buddies();
      for i in range(0,len(buddies)):
         if buddies[i].isService() == False or buddies[i].isRoom() == False:
            # Add as a check
            check = gtk.CheckButton(str(buddies[i].name));
            check.show();
            self.checks.append((check,buddies[i]));
            box.pack_start(check,False,False);

      scrolledwindow = gtk.ScrolledWindow();
      scrolledwindow.add_with_viewport(box);
      scrolledwindow.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC);
      scrolledwindow.show();
      table.attach(scrolledwindow,1,2,1,2,gtk.EXPAND|gtk.FILL);
      
      
      table.show();
      table.set_row_spacings(4);
      table.set_col_spacings(4);
      self.get_content_area().add(table);
